/*
 *  istream.cpp
 *  FrostOS
 *
 *  Created by Alex on 12/4/09.
 *  Copyright 2009 HVS (Hacking vs. Security) and © bluechill. All rights reserved.
 *
 */
#include "istream.h"
#include "ostream.h"
#include <common.h>
#include <irq.h>
#include <string.h>
#include <ctype.h>
#include "keyboard.h"
#include <_null.h>

namespace std {
	
	IStream cin;
	PasswordStream password_cin;
	
	void IStream::getKey(char keyEntered)
	{
		key = keyEntered;
	}
	
	IStream& IStream::operator>>(char *cp)
	{
		int i = 0;
		while (true)
		{
			if (key == '\n' || key == '\r')
			{
				cout.put('\n');
				key = NULL;
				break;
			}
			else if (key == '\b')
			{
				cp[i-1] = ' ';
				i--;
				key = NULL;
			}
			else if (key != NULL)
			{
				cout << key;
				cp[i] = key;
				i++;
				key = NULL;
			}
			key = NULL;
		}
		return *this;
	}
	
	IStream& IStream::operator>>(string& cp)
	{
		int i = 0;
		while (true)
		{
			if (key == '\n' || key == '\r')
			{
				cout.put('\n');
				key = NULL;
				break;
			}
			else if (key == '\b')
			{
				cp[i-1] = ' ';
				i--;
				key = NULL;
			}
			else if (key != NULL)
			{
				cout << key;
				cp[i] = key;
				i++;
				key = NULL;
			}
			key = NULL;
		}
		return *this;
	}
}